<template>
	<!-- 顶部 -->
	<view>
		<view class="table-header">
			<view v-for="index in 8" :key="index"
				:class="{'table-header-item':index!==1,'table-header-item-left':index==1}">
				<view class="header-item-wrap">
					<view v-if="index==1" class="monthTag">
						<view>课程</view>
					</view>
					<view v-else :class="{'weekDay':true,'todayTag':index==3}">
						<view>
							周{{getDayOfWeek(index-1)}}
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="table" v-if="this.islogin==true">
			<view v-for="column in 8" :class="{'table-item-wrap':column!==1,'table-item-left-wrap':column==1}"
				:key="column">
				<!-- 侧边栏 -->
				<view v-if="column==1" v-for="(item,rowindex) in this.row" :key="rowindex">
					<view class="table-item-left table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{item}}
						</view>
					</view>
				</view>

				<!-- 星期一 -->
				<view v-if="column==2" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(0,1).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期二 -->
				<view v-if="column==3" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(1,2).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期三 -->
				<view v-if="column==4" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(2,3).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期四 -->
				<view v-if="column==5" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(3,4).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期五 -->
				<view v-if="column==6" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(4,5).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期六 -->
				<view v-if="column==7" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(5,6).toString().slice(4,100)}}
						</view>
					</view>
				</view>

				<!-- 星期日 -->
				<view v-if="column==8" v-for="(course,index) in this.courseName.slice(0,9)" :key="index">
					<view class="table-item-body table-item" :style="[{height: windowHeight}]">
						<view class="time">
							{{course.curriCulumData.split(",").slice(6,7).toString().slice(4,100)}}
						</view>
					</view>
				</view>

			</view>

		</view>
		
		<view v-else class="nologin">
			<image class="bg-img" src="../../static/index/kcb.jpg"></image>
		</view>
		
	</view>


</template>

<script>
	export default {
		data() {
			return {
				windowHeight: "15vh",
				row: [1, 2, 3, 4, 5, 6, 7, 8, 9],
				courseName: "",
				Course: "",
				islogin: ''
			}
		},
		onLoad() {
			this.studentClass = wx.getStorageSync('studentclass');
			this.token = wx.getStorageSync('token');
			this.openid = wx.getStorageSync('openid');
			if (this.token || this.openid) {
				this.islogin = true
			} else {
				this.islogin = false
			}
		},
		mounted() {
			this.getCourseAll()
		},
		methods: {
			getDayOfWeek(index) {
				switch (index) {
					case 1:
						return "一"
					case 2:
						return "二"
					case 3:
						return "三"
					case 4:
						return "四"
					case 5:
						return "五"
					case 6:
						return "六"
					case 7:
						return "日"
				}
			},

			

			getCourseAll() {
				uni.request({
					url: `https://backendth.flymi.top/curriculum/${this.studentClass}`,
					method: 'GET',
					data: {},
					success: res => {
						this.courseName = res.data.data;
					},
					fail: () => {},
					complete: () => {}
				});
			},

		}
	}
</script>

<style>
	.bg-img {
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		z-index: -1;
	}
	.wait {
		font-size: 28px;
		font-weight: 900;
		color: black;
		padding-left: 35vw;

	}

	.header-item-week {
		display: flex;
		flex-direction: row;
	}

	.table-header {
		display: flex;
		flex-direction: row;
		text-align: center;
		font-size: .7em;
		border: #E4E7ED .1rpx solid;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
	}

	.table-header-item {
		flex: 1;
	}

	.table-header-item-left {
		width: 30px;
	}

	.table {
		display: flex;
		text-align: center;
		background-color: #fdfdfd;
	}

	.table-item {
		margin-top: 8rpx;
		margin-bottom: 8rpx;
		margin-left: 6rpx;
		margin-right: 6rpx;
		border-radius: 8rpx;
		box-shadow: 1px 1px 2px .1px #b6b6b6;
		text-align: center;
		align-self: center;
		align-items: center;
		justify-content: center;
		display: flex;
		word-break: break-all;
		overflow: hidden;
		font-size: .7em;
		color: #ffffff;
		font-weight: bold;
		box-sizing: border-box;
	}

	.table-item-wrap {
		flex: 1;
		background-color: aliceblue;
	}

	.table-item-left-wrap {
		background-color: seashell;
		width: 30px;
		height: 100%;
	}


	.table-item-left {
		box-sizing: border-box;
		color: #040038;
		border-radius: 5rpx;
		width: 30px;
		position: relative;
		font-size: .8em;
		padding: 1rpx;
		box-shadow: 0 0px 0px #ccc;
		display: flex;
		flex-direction: column;
	}

	.time {
		text-align: center;
		align-self: center;
		margin: 11rpx;
		color: salmon;
	}

	.table-item-body {
		background-color: white;
		margin-top: 8rpx;
		margin-bottom: 8rpx;
		margin-left: 6rpx;
		margin-right: 6rpx;
		border-radius: 8rpx;
		box-shadow: 1px 1px 2px .1px #b6b6b6;
		text-align: center;
		align-self: center;
		align-items: center;
		justify-content: center;
		display: flex;
		word-break: break-all;
		overflow: hidden;
		font-size: .7em;
		color: #ffffff;
		font-weight: bold;
		box-sizing: border-box;
	}
</style>
